﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using nplJobsCommon.Employeer;

namespace nplJobsDAL.Select
{
    public class SelectEmployeerType :DataAccessBase
    {
        public SelectEmployeerType()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectEmployeerType.ToString();
        }

        #region GetEmployeerType
        public List<EmployeerType> GetEmployeerType()
        {
            DataBaseHelper dbHelper;
            DataSet dsEmployeerType;

            try
            {
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dsEmployeerType = dbHelper.Run(base.ConnectionString);
                return GetList(dsEmployeerType);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public List<EmployeerType> GetEmployeerTypeWithJobCount()
        {
            DataBaseHelper dbHelper;
            DataSet dsEmployeerType;

            try
            {
                dbHelper = new DataBaseHelper(StoredProcedure.Name.spSelectEmployeerTypeWithJobCount.ToString());
                dsEmployeerType = dbHelper.Run(base.ConnectionString);
                return GetList(dsEmployeerType);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region GetList
        private List<EmployeerType> GetList(DataSet dsEmployeerType)
        {
            List<EmployeerType> employeerType;
            try
            {
                employeerType = (from n in dsEmployeerType.Tables[0].AsEnumerable()
                                 select new EmployeerType
                                   {
                                       ID = n.Field<int>("ID"),
                                       Type = n.Field<string>("Type")
                                   }).ToList();

                return employeerType;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion
    }
}
